﻿using System.Windows;
using Startup.Shell.Domain;
using Startup.Shell.ModelDesignerPreview;

namespace Startup.Shell.Modules.PreviewDesignerCtrlModule
{
	/// <summary>
	/// Interaction logic for PreviewDesignerCtrlModule.xaml
	/// </summary>
	public partial class PreviewDesignerCtrlModule
	{
		public PreviewDesignerCtrlModule()
		{
			InitializeComponent();
		}

		protected override void OnDragEnter(DragEventArgs e)
		{
			if (!e.Data.GetDataPresent("IDesignerPreview") && !e.Data.GetDataPresent("StartupProperty"))
			{
				e.Effects = DragDropEffects.None;
			}

			base.OnDragEnter(e);
		}

		protected override void OnDrop(DragEventArgs e)
		{
			var viewModel = (PreviewDesignerCtrlModelView)DataContext;

			if (e.Data.GetDataPresent("IDesignerPreview"))
			{
				var preview = (IDesignerPreview)e.Data.GetData("IDesignerPreview");
				viewModel.PreviewContainer.Preview = preview.CreateInstance();
			}
			else if (e.Data.GetDataPresent("StartupProperty"))
			{
				var propperty = (StartupProperty)e.Data.GetData("StartupProperty");
				viewModel.PreviewContainer.DataContextPropertyId = propperty.Id;
			}

			base.OnDrop(e);
		}
	}
}
